

#include <SoftwareSerial.h>
SoftwareSerial Blue(0, 1);
long int data;
int nob = 0; // variable resistor connected to analog pin A0
int nobdata = 0;
long int password1 = 92;// forward
long int password2 = 91;// reverse
long int password3 = 71; // right 
long int password4 = 79;// left
long int password5 = 89; // stop

char state = 0;

int urmw1 = 2; // up right motor wire 1 
int urmw2 = 3; // up right motor wire2 

int drmw1 = 4; // down right motor wire1
int drmw2 = 5; // down right motor wire2 

int ulmw1 = 6; // up left motor wire1
int ulmw2 = 7; // up left motor wire2

int dlmw1 = 8; // down left motor wire1
int dlmw2 = 9; // down left motor wire2

int bdm = 11; // brushless dc motor
void setup()
{
pinMode(bdm, OUTPUT);
pinMode(nob, INPUT);
pinMode(urmw1, OUTPUT);
pinMode(urmw2, OUTPUT);
pinMode(drmw1, OUTPUT); 
pinMode(drmw2, OUTPUT); 

pinMode(ulmw1, OUTPUT); 
pinMode(ulmw2, OUTPUT); 
pinMode(dlmw1, OUTPUT); 
pinMode(dlmw2, OUTPUT); 

// keep all the motors off by default
digitalWrite(urmw1, LOW);
digitalWrite(urmw2, LOW);
digitalWrite(drmw1, LOW);
digitalWrite(drmw2, LOW);

digitalWrite(ulmw1, LOW);
digitalWrite(ulmw2, LOW);
digitalWrite(dlmw1, LOW);
digitalWrite(dlmw2, LOW);


Serial.begin(9600);
Blue.begin(9600);

delay(1000);

}

void loop()
{

 // while(Blue.available()==0) ;

nobdata = analogRead(nob);
nobdata = map(nobdata, 0, 1024, 0, 255);
analogWrite(bdm,nobdata);
//Serial.println(nobdata);
delay(20);

 if(Blue.available()>0) 
{
data = Blue.parseInt();

delay(200);
} 
//delay(1000);
//Serial.print(data);

if (data == password1)  // forward
{
digitalWrite(urmw1, HIGH);
digitalWrite(urmw2, LOW);
digitalWrite(drmw1, HIGH);
digitalWrite(drmw2, LOW);

digitalWrite(ulmw1, LOW);
digitalWrite(ulmw2, HIGH);
digitalWrite(dlmw1, LOW);
digitalWrite(dlmw2, HIGH);
  
  data = 45; // garbage value to stop repetition
  Serial.println("Forward");


   }
   
   if( data == password2) // reverse
   {

digitalWrite(urmw1, LOW);
digitalWrite(urmw2, HIGH);
digitalWrite(drmw1, LOW);
digitalWrite(drmw2, HIGH);

digitalWrite(ulmw1, HIGH);
digitalWrite(ulmw2, LOW);
digitalWrite(dlmw1, HIGH);
digitalWrite(dlmw2, LOW);
 data = 45; // garbage value to stop repetition
  Serial.println("Reverse");

   } else

   if( data == password3) // right
   {
 digitalWrite(urmw1, LOW);
digitalWrite(urmw2, HIGH);
digitalWrite(drmw1, LOW);
digitalWrite(drmw2, HIGH);

digitalWrite(ulmw1, LOW);
digitalWrite(ulmw2, HIGH);
digitalWrite(dlmw1, LOW);
digitalWrite(dlmw2, HIGH);
    data = 45; // garbage value to stop repetition
     
  Serial.println("right");

   }
else


   if( data == password4) // left
   {

digitalWrite(urmw1, HIGH);
digitalWrite(urmw2, LOW);
digitalWrite(drmw1, HIGH);
digitalWrite(drmw2, LOW);

digitalWrite(ulmw1, HIGH);
digitalWrite(ulmw2, LOW);
digitalWrite(dlmw1, HIGH);
digitalWrite(dlmw2, LOW);
  data = 45; // garbage value to stop repetition
 Serial.println("Left");

   }
   else
      if( data == password5) // stop
   {
 digitalWrite(urmw1, LOW);
digitalWrite(urmw2, LOW);
digitalWrite(drmw1, LOW);
digitalWrite(drmw2, LOW);

digitalWrite(ulmw1, LOW);
digitalWrite(ulmw2, LOW);
digitalWrite(dlmw1, LOW);
digitalWrite(dlmw2, LOW);
  data = 45; // garbage value to stop repetition
Serial.println("stop");

   }
 
 }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <SoftwareSerial.h>
SoftwareSerial Blue(0, 1);
long int data;
int nob = 0; // variable resistor connected to analog pin A0
int nobdata = 0;
long int password1 = 92;// forward
long int password2 = 91;// reverse
long int password3 = 71; // right 
long int password4 = 79;// left
long int password5 = 89; // stop
 
char state = 0;
 
int urmw1 = 2; // up right motor wire 1 
int urmw2 = 3; // up right motor wire2 
 
int drmw1 = 4; // down right motor wire1
int drmw2 = 5; // down right motor wire2 
 
int ulmw1 = 6; // up left motor wire1
int ulmw2 = 7; // up left motor wire2
 
int dlmw1 = 8; // down left motor wire1
int dlmw2 = 9; // down left motor wire2
 
int bdm = 11; // brushless dc motor
void setup()
{
pinMode(bdm, OUTPUT);
pinMode(nob, INPUT);
pinMode(urmw1, OUTPUT);
pinMode(urmw2, OUTPUT);
pinMode(drmw1, OUTPUT); 
pinMode(drmw2, OUTPUT); 
 
pinMode(ulmw1, OUTPUT); 
pinMode(ulmw2, OUTPUT); 
pinMode(dlmw1, OUTPUT); 
pinMode(dlmw2, OUTPUT); 
 
// keep all the motors off by default
digitalWrite(urmw1, LOW);
digitalWrite(urmw2, LOW);
digitalWrite(drmw1, LOW);
digitalWrite(drmw2, LOW);
 
digitalWrite(ulmw1, LOW);
digitalWrite(ulmw2, LOW);
digitalWrite(dlmw1, LOW);
digitalWrite(dlmw2, LOW);
 
 
Serial.begin(9600);
Blue.begin(9600);
 
delay(1000);
 
}
 
void loop()
{
 
 // while(Blue.available()==0) ;
 
nobdata = analogRead(nob);
nobdata = map(nobdata, 0, 1024, 0, 255);
analogWrite(bdm,nobdata);
//Serial.println(nobdata);
delay(20);
 
 if(Blue.available()>0) 
{
data = Blue.parseInt();
 
delay(200);
} 
//delay(1000);
//Serial.print(data);
 
if (data == password1)  // forward
{
digitalWrite(urmw1, HIGH);
digitalWrite(urmw2, LOW);
digitalWrite(drmw1, HIGH);
digitalWrite(drmw2, LOW);
 
digitalWrite(ulmw1, LOW);
digitalWrite(ulmw2, HIGH);
digitalWrite(dlmw1, LOW);
digitalWrite(dlmw2, HIGH);
  
  data = 45; // garbage value to stop repetition
  Serial.println("Forward");
 
 
   }
   
   if( data == password2) // reverse
   {
 
digitalWrite(urmw1, LOW);
digitalWrite(urmw2, HIGH);
digitalWrite(drmw1, LOW);
digitalWrite(drmw2, HIGH);
 
digitalWrite(ulmw1, HIGH);
digitalWrite(ulmw2, LOW);
digitalWrite(dlmw1, HIGH);
digitalWrite(dlmw2, LOW);
 data = 45; // garbage value to stop repetition
  Serial.println("Reverse");
 
   } else
 
   if( data == password3) // right
   {
 digitalWrite(urmw1, LOW);
digitalWrite(urmw2, HIGH);
digitalWrite(drmw1, LOW);
digitalWrite(drmw2, HIGH);
 
digitalWrite(ulmw1, LOW);
digitalWrite(ulmw2, HIGH);
digitalWrite(dlmw1, LOW);
digitalWrite(dlmw2, HIGH);
    data = 45; // garbage value to stop repetition
     
  Serial.println("right");
 
   }
else
 
 
   if( data == password4) // left
   {
 
digitalWrite(urmw1, HIGH);
digitalWrite(urmw2, LOW);
digitalWrite(drmw1, HIGH);
digitalWrite(drmw2, LOW);
 
digitalWrite(ulmw1, HIGH);
digitalWrite(ulmw2, LOW);
digitalWrite(dlmw1, HIGH);
digitalWrite(dlmw2, LOW);
  data = 45; // garbage value to stop repetition
 Serial.println("Left");
 
   }
   else
      if( data == password5) // stop
   {
 digitalWrite(urmw1, LOW);
digitalWrite(urmw2, LOW);
digitalWrite(drmw1, LOW);
digitalWrite(drmw2, LOW);
 
digitalWrite(ulmw1, LOW);
digitalWrite(ulmw2, LOW);
digitalWrite(dlmw1, LOW);
digitalWrite(dlmw2, LOW);
  data = 45; // garbage value to stop repetition
Serial.println("stop");
 
   }
 
 }